<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* @framework : Codeigniter Framework
*
* @author: fatangel26
*
*/

	class Slide_model extends CI_Model
	{
	    protected $_table;

		public function __construct()
		{
			parent::__construct();

            $this->load->database();

            $this->_table = 'tbl_slideshow';
		}

        /*Basic Method*/

        public function select($data = array())
        {
            if(empty($data))
            {
                $query = $this->db->order_by('slide_id', 'desc')
                                  ->get($this->_table);

                if($query->num_rows() > 0)
                    return $query->result_object();
            }
            else
            {
                $query = $this->db->get_where($this->_table, $data);

                if($query->num_rows() > 0)
                    return $query->row();
            }

            return FALSE;
        }

        public function delete($slide_id)
        {
            $query = $this->db->delete($this->_table, array('slide_id' => $slide_id));

            if($this->db->affected_rows() > 0)
                return TRUE;
            return FALSE;
        }

        public function create($data = array())
        {
            if(!empty($data))
            {
                $this->db->set('slide_created', 'NOW()', FALSE);

                $query = $this->db->insert($this->_table, $data);
            }

            if($this->db->affected_rows() > 0)
                return TRUE;
            return FALSE;
        }

        public function edit($slide_id, $data = array())
        {
            if(isset($data['slide_link']))
                $this->db->set('slide_link', $data['slide_link']);
            if(isset($data['slide_image']))
                $this->db->set('slide_image', $data['slide_image']);
            if(isset($data['slide_image_thumb']))
                $this->db->set('slide_image_thumb', $data['slide_image_thumb']);
            if(isset($data['slide_order']))
                $this->db->set('slide_order', $data['slide_order']);
            if(isset($data['slide_status']))
                $this->db->set('slide_status', $data['slide_status']);
            if(isset($data['slide_des']))
                $this->db->set('slide_des', $data['slide_des']);

            $this->db->where('slide_id', $slide_id);

            if($this->db->update($this->_table))
                return TRUE;
            return FALSE;
        }

        /*Magic Method*/

	}

/* End of file Pages_model.php */
/* Location: ./models/frontend/_model.php */